﻿namespace GenFu.Web;

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

using System;
using System.Runtime.Loader;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllersWithViews();
        services.AddMemoryCache();
        services.AddSession(s =>
        {
            s.IdleTimeout = TimeSpan.FromMinutes(1);
        });

        //add a Assembly Loader to services
        services.AddScoped<AssemblyLoadContext, AssemblyLoadContext>(x =>
        {
            return AssemblyLoadContext.Default;
        });
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseStaticFiles();
        app.UseRouting();
        app.UseSession();

        app.UseEndpoints(routes =>
        {
            routes.MapDefaultControllerRoute();
        });
    }
}
